#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m;
ll a[1000010];
ll t;
ll c[100010];
ll k;
ll j[100010];
int main()
{
	freopen("arena.in","r",stdin);
	freopen("arena.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	srand(time(0));
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	    cin>>a[i];
	for(int i=1;i<=m;i++)
	    cin>>c[i];
	k=log(n)/log(2);
	if(pow(2,k)!=n)
	    k++;
	for(int i=1;i<=k;i++)
	    cin>>j[i];
	cin>>t;
	for(int i=1;i<=t;i++)
	{
		int a1,a2,a3,a4;
		cin>>a1>>a2>>a3>>a4;
	}
	for(int i=1;i<=t;i++)
	    cout<<rand()%100001<<endl;
	return 0;
}
